package com.group3.controller;

import com.group3.common.result.ApiResponse;
import com.group3.common.topic.LiveTopic;
import com.group3.common.topic.OrderTopic;
import com.group3.model.Order;
import com.group3.service.OrderSevice;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping ("/mq")
public class MqOrderController {
    @Autowired
    RocketMQTemplate rocketMQTemplate;
    @Autowired
    OrderSevice orderSevice;
    @RequestMapping ("/sendpayOrder/{oid}")
    public ApiResponse sendpayOrder(@PathVariable  Integer oid) {
        Order order = orderSevice .getOrderByOid(oid);
        rocketMQTemplate.convertAndSend(OrderTopic.ORDER_PAY, order);
        log.info("订单支付成功:{}", order);
         return ApiResponse.success("订单支付成功");
    }

    // 新增方法
    @RequestMapping("/sendSeckillOrder")
    public ApiResponse sendSeckillOrder(@RequestParam Integer orderId) {
        rocketMQTemplate.convertAndSend(LiveTopic.LIVE_SECKILL_ORDER, orderId);
        log.info("秒杀订单消息已发送，订单ID：{}", orderId);
        return ApiResponse.success("秒杀订单消息发送成功");
    }
}
